package com.guigu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.guigu.bean.Life;
import com.guigu.bean.LifeExample;
import com.guigu.bean.LifeExample.Criteria;
import com.guigu.dao.LifeMapper;

/**
 * @author wangzibin
 *生活记录的CRUD
 */
@Service
public class LifeServices {
	@Autowired
	LifeMapper lifeMapper;
	
	/**
	 * 生活通过日期模糊查询
	 * @param vagueDate
	 * @param userId
	 * @return
	 */
	public List<Life> getLifesByVagueDate(String vagueDate,int userId){
		if (vagueDate==null||userId==0) {
			return null;
		}else {
			LifeExample example=new LifeExample();
			Criteria criteria=example.createCriteria();
			criteria.andLifeTimeVagueLike(vagueDate).andUseridEqualTo(userId);
			return lifeMapper.selectByExample(example);
		}
	}
	
	/**
	 * 生活保存
	 * @param life
	 */
	public void saveLife(Life life){
		lifeMapper.insertSelective(life);
	}
	
	
	/**
	 * 生活修改
	 * @param life
	 */
	public void updateLife(Life life){
		lifeMapper.updateByPrimaryKeySelective(life);
	}
	
	/**
	 * 生活删除
	 * @param lifeId
	 */
	public void deleteByLifeId(Integer lifeId){
		lifeMapper.deleteByPrimaryKey(lifeId);
	}
}
